<?PHP
error_reporting(E_ALL ^ E_NOTICE);
function DefaultErrorHandler($errno, $errstr, $errfile, $errline)
{
	echo "Error in file: $errfile ($errline: #$errno) $errstr.<br/>\n";

	return false;
}
set_error_handler('DefaultErrorHandler');
if ( function_exists('date_default_timezone_set') )
{
	//date_default_timezone_set('America/New_York');
}
else
{
	echo "not exists<br/>\n";
}
require_once "Database.php";
require_once 'webApplication/webApplication.php';
require_once 'xmlResult.php';
require_once 'webControls/webControls.php';
require_once 'appControls/appControls.php';

error_reporting(E_ALL ^ E_NOTICE);

$writer = new HtmlWriter();
$parser = new Parser();

$defaultPage = "main.xml";
if ( isset($_SERVER["PATH_INFO"]) && !empty( $_SERVER["PATH_INFO"]) )
{
	$path = $_SERVER["PATH_INFO"];
	$parts = explode('.', $path);
	$ext = end($parts);
	if ( $ext == 'app' )
	{
		$defaultPage = substr($path, 0, -3)."xml";
	}
}

$page = $parser->make($defaultPage);

$page->OnInit($parser, array());

foreach ($_POST as $name=>$value )
{
	// RisePostEvents
	if ( $control = $page->findControl($name) )
	{
		$control->RiseEvents();
	}
}

if ( $page->template )
{
	$page->template->RenderChildren($writer);
}
else
{
	$page->RenderChildren($writer);
}
echo $writer->getContent();

function loadTemplate($tplName, $context)
{
	extract($context);
	ob_start();
	include ($tplName);
	$html = ob_get_contents();
	ob_clean();

	return $html;
}
?>
